import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';

import 'http_uts.dart';

class HttpService {
  ///项目列表
  static Future<void> projectList(
      int page, String cid, HttpCallback callback) async {
    HttpUts.request("/project/list/$page/json?cid=$cid",
        callback: callback, method: HttpUts.GET);
  }

  ///项目
  static Future<void> project(HttpCallback callback) async {
    HttpUts.request("/project/tree/json",
        callback: callback, method: HttpUts.GET);
  }

  ///问答
  static Future<void> wenda(int page, HttpCallback callback) async {
    HttpUts.request("/wenda/list/$page/json",
        callback: callback, method: HttpUts.GET);
  }

  ///置顶文章
  static Future<void> topArticleList(HttpCallback callback) async {
    HttpUts.request("/article/top/json",
        callback: callback, method: HttpUts.GET);
  }

  ///banner
  static Future<void> bannerList(HttpCallback callback) async {
    HttpUts.request("/banner/json", callback: callback, method: HttpUts.GET);
  }

  ///登录
  static Future<void> login(
      String user_name, String pass_word, HttpCallback callback) async {
    HttpUts.request("/user/login",
        formData: FormData.fromMap({
          "username": "$user_name",
          "password": "$pass_word",
        }),
        callback: callback,
        method: HttpUts.POST);
  }

  ///获取个人积分，需要登录后访问
  static Future<void> userInfo(HttpCallback callback) {
    HttpUts.request("/lg/coin/userinfo/json", callback: callback);
  }

  ///获取和人积分排行
  static Future<void> coin(int page, {HttpCallback callback}) {
    HttpUts.request("/coin/rank/$page/json", callback: callback);
  }

  /// 获取我的收藏
  static Future<void> myCollectionData(int page, {HttpCallback callback}) {
    HttpUts.request(
      "/lg/collect/list/$page/json",
      callback: callback,
    );
  }

  ///收藏文章
  static Future<void> collect(String id, {HttpCallback callback}) {
    HttpUts.request(
      "/lg/collect/$id/json",
      callback: callback,
      method: HttpUts.POST,
    );
  }

  ///取消收藏
  static Future<void> unCollect(String id, {HttpCallback callback}) {
    HttpUts.request(
      "/lg/uncollect_originId/$id/json",
      callback: callback,
      method: HttpUts.POST,
    );
  }
}
